﻿using Cysharp.Threading.Tasks;
using UnityEngine;

namespace uMVP
{
    public static class ViewExtends
    {
        public static void  InitializeAsync(this IView view)
        {
            view.OnInitializeAsync().Forget();
        }
        
        public static async UniTask InitializeAsync<TPresenterInterface>(this IView<TPresenterInterface> view, TPresenterInterface presenter) where TPresenterInterface : class
        {
            view.SetPresenter(presenter);
            await view.OnInitializeAsync();
        }
        
        public static async UniTask InitializeAsync<TPresenterInterface, TPresenterFactory>(this IView<TPresenterInterface, TPresenterFactory> view, 
            TPresenterFactory factory) where TPresenterInterface : class
        {
            var presenter = view.OnCreatePresenter(factory);
            await view.InitializeAsync(presenter);
        }
    }
}